@extends('Admin.Layouts.index')

@section('content')

<div class="box-content">
    <div >
        <form action="{{url('admin/user')}}" method="get">
        <div class="row-fluid">
              <div id="DataTables_Table_1_length" class="dataTables_length">
            <label>显示 
                <select size="1" name="count">
                    <option value="10" @if(!empty($req['count']) && $req['count'] == 10) selected @endif>10</option>
                    <option value="20" @if(!empty($req['count']) && $req['count'] == 20) selected @endif>20</option>
                    <option value="30" @if(!empty($req['count']) && $req['count'] == 30) selected @endif>30</option>
                    <option value="50" @if(!empty($req['count']) && $req['count'] == 50) selected @endif>50</option>
                </select>条
            </label>
        </div>
            <div class="span6" style="float:right;margin-top:-50px;margin-right: -180px; ">
                <div class="dataTables_filter" id="DataTables_Table_0_filter">
                    <label>
                        
                            <font style="vertical-align: inherit;">
                                <font style="vertical-align: inherit;">
                                </font>
                            </font>
                        <input type="text" style="height: 27px;margin-top:10px;" name="search" aria-controls="DataTables_Table_0">
                        <input type="submit" class="btn-info btn-xm" value="搜索">  
                  </label>
                </div>
            </div>
        </div>
        </form>
        <table class="table table-striped table-bordered bootstrap-datatable datatable dataTable"
        id="DataTables_Table_0" aria-describedby="DataTables_Table_0_info">
         <div class="box-header" data-original-title="">
            <h2><i class="halflings-icon white user"></i><span class="break"></span><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">用户列表</font></font></h2>
            <div class="box-icon">
                <a href="#" class="btn-setting"><i class="halflings-icon white wrench"></i></a>
                <a href="#" class="btn-minimize"><i class="halflings-icon white chevron-up"></i></a>
                <a href="#" class="btn-close"><i class="halflings-icon white remove"></i></a>
            </div>
         </div>
            <tr role="row">
            <th class="sorting_asc" role="columnheader" tabindex="0" aria-controls="DataTables_Table_0"
                rowspan="1" colspan="1" aria-sort="ascending" aria-label="Username: activate to sort column descending"
                style="width: 129px;">
                    <font style="vertical-align: inherit;">
                        <font style="vertical-align: inherit;">
                            ID
                        </font>
                    </font>
                </th>
                <th class="sorting_asc" role="columnheader" tabindex="0" aria-controls="DataTables_Table_0"
                rowspan="1" colspan="1" aria-sort="ascending" aria-label="Username: activate to sort column descending"
                style="width: 129px;">
                    <font style="vertical-align: inherit;">
                        <font style="vertical-align: inherit;">
                            用户名
                        </font>
                    </font>
                </th>
                 <th class="sorting" role="columnheader" tabindex="0" aria-controls="DataTables_Table_0"
                rowspan="1" colspan="1" aria-label="Date registered: activate to sort column ascending"
                style="width: 191px;">
                    <font style="vertical-align: inherit;">
                        <font style="vertical-align: inherit;">
                            昵称  
                        </font>
                    </font>
                </th>
                 <th class="sorting" role="columnheader" tabindex="0" aria-controls="DataTables_Table_0"
                rowspan="1" colspan="1" aria-label="Date registered: activate to sort column ascending"
                style="width: 191px;">
                    <font style="vertical-align: inherit;">
                        <font style="vertical-align: inherit;">
                            性别  
                        </font>
                    </font>
                </th>
                 <th class="sorting" role="columnheader" tabindex="0" aria-controls="DataTables_Table_0"
                rowspan="1" colspan="1" aria-label="Date registered: activate to sort column ascending"
                style="width: 191px;">
                    <font style="vertical-align: inherit;">
                        <font style="vertical-align: inherit;">
                            年龄  
                        </font>
                    </font>
                </th>
                 <th class="sorting" role="columnheader" tabindex="0" aria-controls="DataTables_Table_0"
                rowspan="1" colspan="1" aria-label="Date registered: activate to sort column ascending"
                style="width: 191px;">
                    <font style="vertical-align: inherit;">
                        <font style="vertical-align: inherit;">
                            爱好 
                        </font>
                    </font>
                </th>
                <th class="sorting" role="columnheader" tabindex="0" aria-controls="DataTables_Table_0"
                rowspan="1" colspan="1" aria-label="Date registered: activate to sort column ascending"
                style="width: 191px;">
                    <font style="vertical-align: inherit;">
                        <font style="vertical-align: inherit;">
                            手机号
                        </font>
                    </font>
                </th>
                
                <th class="sorting" role="columnheader" tabindex="0" aria-controls="DataTables_Table_0"
                rowspan="1" colspan="1" aria-label="Date registered: activate to sort column ascending"
                style="width: 191px;">
                    <font style="vertical-align: inherit;">
                        <font style="vertical-align: inherit;">
                            邮箱
                        </font>
                    </font>
                </th>
                <th class="sorting" role="columnheader" tabindex="0" aria-controls="DataTables_Table_0"
                rowspan="1" colspan="1" aria-label="Actions: activate to sort column ascending"
                style="width: 224px;">
                    <font style="vertical-align: inherit;">
                        <font style="vertical-align: inherit;">
                            操作
                        </font>
                    </font>
                </th>
            </tr>
                @foreach($user as $k=>$v)
                <tr class="odd">
                     <td class=" sorting_1">
                        <font style="vertical-align: inherit;">
                            <font style="vertical-align: inherit;">
                                {{$v['id']}}
                            </font>
                        </font>
                    </td>
                    <td class=" sorting_1">
                        <font style="vertical-align: inherit;">
                            <font style="vertical-align: inherit;">
                                {{$v['username']}}
                            </font>
                        </font>
                    </td>
                    <td class=" sorting_1">
                        <font style="vertical-align: inherit;">
                            <font style="vertical-align: inherit;">
                                {{$v['nickname']}}
                            </font>
                        </font>
                    </td>
                    <td class=" sorting_1">
                        <font style="vertical-align: inherit;">
                            <font style="vertical-align: inherit;">
                                @if($v['sex'] == 1)
                                    女
                                  @else
                                    男
                                   @endif   
                            </font>
                        </font>
                    </td>
                    <td class=" sorting_1">
                        <font style="vertical-align: inherit;">
                            <font style="vertical-align: inherit;">
                                {{$v['age']}}
                            </font>
                        </font>
                    </td>
                    <td class=" sorting_1">
                        <font style="vertical-align: inherit;">
                            <font style="vertical-align: inherit;">
                                {{$v['like']}}
                            </font>
                        </font>
                    </td>
                    <td class="center ">
                        <font style="vertical-align: inherit;">
                            <font style="vertical-align: inherit;">
                                {{$v['phone']}}
                            </font>
                        </font>
                    </td>
                     <td class="center ">
                        <font style="vertical-align: inherit;">
                            <font style="vertical-align: inherit;">
                                {{$v['email']}}
                            </font>
                        </font>
                    </td>

                    <td class="center ">
                        <a href="{{url('admin/user/'.$v['id'].'/edit')}}" class="btn btn-info btn-sm">修改</a>
                        <a href="javascript:;" onclick="delUser({{$v['id']}})" class="btn btn-warning btn-sm">删除</a>
                    </td>
                </tr>
            @endforeach
        </table>
        <div class="pagination pagination-centered" >
            {!! $user->appends(['search'=>$input])->render() !!}
        </div>
        
        <script type="text/javascript">
                function delUser(userId){
                        layer.confirm('确认删除吗？', {
                            btn: ['确定','取消'] //按钮
                        }, function(){
                            //向服务器发送删除请求
            //              $.ajax(请求的路径，携带的参数，返回的结果)
            //                url===>admin/user/21
                            $.post("{{url('admin/user/')}}/ "+userId,{'_token':'{{csrf_token()}}','_method':'delete'},function(data){
                                   if( data.status == 0){
            //                            将json格式的字符串变成json对象
            //                           var data = JSON.parse(data);
                                       layer.msg(data.msg, {icon: 6});
                                       location.href = location.href;
                                   }else{
                                       layer.msg(data.msg, {icon: 5});
                                       location.href = location.href;
                                   }
                            });
                            //
                        }, function(){

                        });
                }

        </script>
    </div>
</div>
@endsection